// pages/order/order.js
var index = require('../index/index.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (!index.data.userInfo.id) {
      wx.showToast({
        title: '没有绑定账号',
        icon: 'none',
        duration: 2000,
        complete: function (e) {
          console.log(123123)
          setTimeout(function () {
            wx.switchTab({
              url: '../index/index'
            })
          }, 1800)
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    wx.request({
      url: 'https://selwyn.mynatapp.cc/order/findAllOrder', //仅为示例，并非真实的接口地址
      data: {
        userId: index.data.userInfo.id
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: 'post',
      success: function (res) {
        console.log(res.data)
        that.setData({
          order: res.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  delOrder:function(e){
    console.log(this.data.id)
    var that = this
    for(var i =0;i<this.data.text.length;i++){
      wx.request({
        url: 'https://selwyn.mynatapp.cc/order/deteleById', //仅为示例，并非真实的接口地址
        data: {
          id: this.data.text[i]
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        method: 'post',
        success: function (res) {
          console.log(res)
          wx.request({
            url: 'https://selwyn.mynatapp.cc/order/findAllOrder', //仅为示例，并非真实的接口地址
            data: {
              userId: index.data.userInfo.id
            },
            header: {
              'content-type': 'application/json' // 默认值
            },
            method: 'post',
            success: function (res) {
              that.setData({
                order: res.data
              })
            }
          })
        }
      })
    }
    var that = this
    wx.request({
      url: 'https://selwyn.mynatapp.cc/order/findAllOrder', //仅为示例，并非真实的接口地址
      data: {
        userId: 9,//index.data.userInfo.id
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: 'post',
      success: function (res) {
        that.setData({
          order: res.data
        })
      }
    })
  },
  radioChange:function(e){
    var text = [];
    var id = [];
    for (var i = 0; i < e.detail.value.length; i++) {
      var aaa = e.detail.value[i].split(',');
      text = text.concat(aaa[0])
      id = id.concat(aaa[1])
    } 
    this.setData({
      text:text
    })
    // console.log(text)
  },
  confirm:function(e){
    for (var i = 0; i < this.data.text.length; i++) {
      wx.request({
        url: 'https://selwyn.mynatapp.cc/order/confirmById', //仅为示例，并非真实的接口地址
        data: {
          id: this.data.text[i]
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        method: 'post',
        success: function (res) {
          console.log(res)
        }
      })
    }
    var that = this
    wx.request({
      url: 'https://selwyn.mynatapp.cc/order/findAllOrder', //仅为示例，并非真实的接口地址
      data: {
        userId: index.data.userInfo.id
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: 'post',
      success: function (res) {
        that.setData({
          order: res.data
        })
      }
    })
  }
})